<!--用户管理 -->
<template>
    <div class="each-model">

        <div class="page-nav">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-home" style="margin-right: 6px;"></i>代理商管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="page-content">
            <div class="page-content-box">
                <div class="page-content-header">
                    <div class="model-title">
                        <span>代理商管理</span>
                        <div class="add-new-btn">
                            <el-button @click="$router.go(-1)" style="margin-top: 4px;" size="small" type="primary" icon="arrow-left">返回</el-button>
                        </div>
                    </div>
                </div>
                <div class="page-content-main">
                    <div class="model-content">
                        <el-form ref="form" :model="form" :rules="formRules" label-width="130px">
                            <el-form-item label="代理商名称" prop="name">
                                <el-input v-model="form.name" placeholder="代理商名称"></el-input>
                            </el-form-item>
                            <el-form-item label="地址" prop="address">
                                <el-input v-model="form.address" placeholder="地址"></el-input>
                            </el-form-item>
                            <el-form-item label="联系人姓名" prop="contactName">
                                <el-input v-model="form.contactName" placeholder="联系人姓名"></el-input>
                            </el-form-item>
                            <el-form-item label="联系人电话" prop="contactPhone">
                                <el-input v-model="form.contactPhone" placeholder="联系电话"></el-input>
                            </el-form-item>
                            <el-form-item label="QQ" prop="qqAccount">
                                <el-input v-model="form.qqAccount" placeholder="QQ"></el-input>
                            </el-form-item>
                            <el-form-item label="微信" prop="wechatAccount">
                                <el-input v-model="form.wechatAccount" placeholder="微信"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="cancelForm">取 消</el-button>
                            <el-button type="primary" @click="saveForm">确 定</el-button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    export default {
        name: 'custormInfoForm',
        data : function(){
            return {
                form: {
                    name: '',
                    address: '',
                    contactPhone: '',
                    comment: '',
                    contactName:''
                },
                formRules: {
//                    name: [
//                        {required: true, message: '请填写代理商名称', trigger: 'change'}
//                    ],
//                    contactName: [
//                        {required: true, message: '请填写联系人姓名', trigger: 'change'}
//                    ],
//                    contactPhone: [
//                        {required: true, message: '请填写电话', trigger: 'change'}
//                    ]
                }
            }
        },
        methods: {
            cancelForm: function () {
                this.$router.go(-1);
            },
            saveForm:function() {
                var that=this;
                this.$refs["form"].validate(function(valid)
                {
                    if (valid) {
                        if (that.form.id) {
                            that.$rsClient.put("/customerInfo/"+that.form.id, that.form,function (result)
                            {
                                that.$message({message: "修改成功", type: "success"});
                                that.$router.go(-1);
                            }
                        );
                        } else {
                            that.form.status=0;
                            that.$rsClient.post("/customerInfo", that.form, function(result)
                            {
                                that.$message({message: "创建成功", type: "success"});
                                that.$router.go(-1);
                            }
                          );
                        }

                    }
                }
                )
                ;
            },
            getCustomInfo:function(){
                var that=this;
                this.$rsClient.get("/customerInfo/"+this.$route.query.id,function(custom){
                    that.form.name=custom.name;
                    that.form.address=custom.address;
                    that.form.contactPhone=custom.contactPhone;
                    that.form.contactName=custom.contactName;
                    that.form.qqAccount=custom.qqAccount;
                    that.form.wechatAccount=custom.wechatAccount;
                    that.form.id=custom.id;
                });
            }
        },
        components: {
        },
        mounted:function(){
            if(this.$route.query.id){
                this.getCustomInfo();
            }
        }
    }
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>

</style>
